package com.leadingsoft.pwxk.services.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.leadingsoft.pwxk.model.BaseInfo;
import com.leadingsoft.pwxk.repository.BaseInfoRepository;
import com.leadingsoft.pwxk.services.AbstractService;

/**
 * @author: lipan 2018年5月10日
 * @description: ()
 * 
 */

@Service
public class BaseInfoServiceImpl extends AbstractService<BaseInfo> {

	@Autowired
	private BaseInfoRepository baseInfoRepository;

	@Override
	public void saveAll(List<BaseInfo> models) {
		baseInfoRepository.saveAll(models);
	}

	@Override
	public void deleteAll() {
		baseInfoRepository.deleteAll();
	}

	@Override
	public String findLatestTime() {
		Sort sort = new Sort(Direction.DESC, "activetime");
		List<BaseInfo> findAll = baseInfoRepository.findAll(sort);
		if (!findAll.isEmpty() && findAll.size() > 0) {
			return findAll.get(0).getActivetime();
		}
		return null;
	}

	@Override
	public Long getCount() {
		return baseInfoRepository.count();
	}

	@Override
	public void save(BaseInfo model) {
		baseInfoRepository.save(model);
	}
}
